<?php



	/*
	 * All rights Reserved, Designed By www.youyacao.com <br>
	 * @Description:充值 <br>
	 * @version 蜻蜓C影视追剧系统  <br>
	 * @author:成都市一颗优雅草科技有限公司  <br>
	 * 注意：使用我司开源源代码请遵循license文件的协议仅供个人非盈利使用，禁止用于其他的商业用途
	 * 需要商业用途或者定制开发等可访问songshu.youyacao.com  联系QQ:2853810243 422108995 23625059584
	 * 正版系统查询系统 zhengbancha.youyacao.com
	 */
namespace App\Admin\Controllers;

use App\Admin\Repositories\Recharge;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class RechargeController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Recharge(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('name');
            $grid->column('type')->using([0 => '普通充值', 1 => 'VIP充值']);
            $grid->column('price')->editable();
            $grid->column('integral')->editable();
            $grid->column('donate')->editable();
            $grid->column('vip_day', 'VIP天数')->editable();
            $grid->column('desc');
            $grid->column('status')->bool();
            $grid->column('tuijian')->bool();
//            $grid->column('ico');
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Recharge(), function (Show $show) {
            $show->field('id');
            $show->field('name');
            $show->field('price');
            $show->field('donate');
            $show->field('integral');
            $show->field('desc');
            $show->field('status');
//            $show->field('ico');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Recharge(), function (Form $form) {
            $form->display('id');
            $form->text('name')->required();
            $form->currency('price', '价格')->symbol('元')->required();
            $form->radio('type', '类型')
                ->when(0, function (Form $form) {
//                    $form->currency('price')->symbol('元')->required();
                    $form->currency('integral')->symbol('个');
                    $form->currency('donate')->symbol('个');
                })
                ->when(1, function (Form $form) {
                    $form->text('vip_day', '天数');
                })
                ->options([0 => '普通充值', 1 => 'VIP充值'])
                ->default(0);
//            $form->currency('price')->symbol('元')->required();
//            $form->currency('integral')->symbol('个')->required();
//            $form->currency('donate')->symbol('个')->required();
            $form->text('desc')->help('对应充值界面的第三行')->rules('required|max:20');
            $form->radio('status')->options([0=>'禁用',1=>'启用'])->default(1)->required();
            $form->radio('tuijian')->options([1=>'推荐']);
//            $form->image('ico');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
